'use strict'

const Sequelize = require('sequelize'); //操作数据库
const fs = require('fs'); //文件操作
const ApiClient = require('../server/taobao.js').ApiClient; //淘宝API
const Taobao = require('../server/taobao.js').Taobao;
//前台API，可获取授权
/*var config = {
    app_key:"23164248",
    app_secret:"ea9dbcf8c9dddf13b57fcdd8f1f63b32",
    redirect_uri:"http://vrbuy.ews.m.jaeapp.com/oauth2"
}
var frontClient = new ApiClient({
                            'appkey':config.app_key,
                            'appsecret':config.app_secret,
                            'url':'http://gw.api.taobao.com/router/rest'
                        });*/
//后台API，可获取头像 
var config2 = {
    app_key: "23601428",
    app_secret: "18a52be2c3d6e630924c3d72b81580d9"
}
var backClient = new ApiClient({
    'appkey': config2.app_key,
    'appsecret': config2.app_secret,
    'url': 'http://gw.api.taobao.com/router/rest'
});

var secretKey = {
    key: '751f620ea3c8f930',
    iv: '2624750004398718',
}

//微信
var WxApi = require('../server/wxApi');
var config = {
    appId: 'wx6d5c659db53fee95',
    appSecret: 'd62213dea308cb61f6c3e5b4fe649468',
    cachepath: 'morefunWxtoken'
}
var wxApi = new WxApi(config, {});

exports.register = function (server, option, next) {

    /*
        const sequelize = server.app.sequelize;

        var dataBase = {
            //团购iteam表
            groupon_fotile_iteam : sequelize.define('groupon_fotile_iteam',{
                iteam_id:{
                    type: Sequelize.INTEGER,
                    primaryKey: true,
                    autoIncrement: true
                }
            },{
                freezeTableName:true,
                timestamps:true,
                underscoredAll:true
            }),
            //团购user表
            groupon_fotile_user : sequelize.define('groupon_fotile_user',{
                user_id:{
                    type: Sequelize.INTEGER,
                    primaryKey: true,
                    autoIncrement: true
                },
                wechat_id:{
                    type: Sequelize.STRING
                },
                taobao_id:{
                    type: Sequelize.STRING
                },
                wangwang_id:{
                    type: Sequelize.STRING
                },
                avatar:{//头像
                    type: Sequelize.STRING
                },
                realname:{
                    type: Sequelize.STRING
                },
                telephone:{
                    type: Sequelize.STRING
                },
                iteam_id:{
                    type: Sequelize.INTEGER
                },
                service:{
                    type: Sequelize.STRING
                }
            },{
                freezeTableName:true,
                timestamps:true,
                underscoredAll:true
            })
        }

        var dataFn = require('../server/groupon')(dataBase,sequelize);
    */



    var dataFn = require('../server/skintest')(backClient);


    server.route({
        method: ['GET', 'POST'],
        path: '/skintest/skininterface/test',
        handler: function (request, reply) {
            var options = request.payload || request.url.query;
            dataFn.skininterface.test(options.mixnick, options.dataURL).then(data => {
                if (data) {
                    return reply(data);
                }
            });
        }
    });
    return next();
}

exports.register.attributes = {
    name: 'route-skintest'
}